package com.kimu.order_service_interface.entity;

import java.util.Arrays;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum OrderStatus {
    UNPAID("未支付", 0),       // 未支付
    PAID("已支付", 1),         // 已支付
    CANCELLED("已取消", 2),    // 已取消
    DELIVERED("已发货", 3),    // 已发货
    COMPLETED("已完成", 4);     // 已完成

    private final String description;
    
    @EnumValue
    private final int code;

    OrderStatus(String description, int code) {
        this.description = description;
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public int getCode() {
        return code;
    }

    // 根据code获取枚举
    public static OrderStatus of(int code) {
        return Arrays.stream(values())
            .filter(e -> e.code == code)
            .findFirst()
            .orElseThrow(() -> new IllegalArgumentException("无效状态码"));
    }
}